﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;

public partial class CustomTool_newproduct : System.Web.UI.UserControl
{
    /// <summary>
    /// 最新产品显示 10 条记录
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindData();
        }
    }

    public void BindData()
    {
        try
        {
            BLL.Business.BookBLL bookbll = new BLL.Business.BookBLL();
            DataSet ds = bookbll.SelectNewBook();
            if ((ds == null) ||
                   (ds.Tables.Count == 0) ||
                   (ds.Tables.Count == 1 && ds.Tables[0].Rows.Count == 0))
            { }
            else
            {
                ds.Tables[0].Columns.Add("sellprice");     // 添加新列（表示订单状态）
                ds.Tables[0].Columns.Add("sellCount");     // 添加新列（表示已卖出）
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    float Book_Priceflo;
                    float Book_Discountflo;
                    int Book_Countint;
                    int Book_ImportCountint;

                    Book_Priceflo = float.Parse(dr[6].ToString());
                    Book_Discountflo = float.Parse(dr[7].ToString());
                    Book_ImportCountint = Int32.Parse(dr[13].ToString());
                    Book_Countint = Int32.Parse(dr[10].ToString());
                    dr["Book_Coverstr"] = "BackManage/UploadPicture/" + dr[8].ToString();     // 设置路径
                    String CC = dr["Book_Coverstr"].ToString();
                    dr["sellprice"] = Book_Priceflo * Book_Discountflo;                       // 现价
                    dr["sellCount"] = System.Math.Abs(Book_ImportCountint - Book_Countint);  // 已卖出
                }
                DataList1.DataSource = ds.Tables[0].DefaultView;
                DataList1.DataBind();
            }
        }
        catch(Exception ex)
        {
            Response.Write("<script>alert('"+ex.Message.ToString()+"')</script>");
        }
    }
}
